package com.hhit.collaborative_learning.learning;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql;

public class CancelFocusServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userId=request.getParameter("userId");
		String c_userId=request.getParameter("c_userId");
		String type=request.getParameter("type");
		HttpSession session=request.getSession();
		int myAttention=Integer.parseInt(session.getAttribute("blog_myAttention")+"");
		int attentionEachOther=Integer.parseInt(session.getAttribute("blog_attentionEachOther")+"");
		int attentionMe=Integer.parseInt(session.getAttribute("blog_attentionMe")+"");
		PublicDaoImplMySql dao=new PublicDaoImplMySql();
		if(dao.cancelFocus(Integer.parseInt(userId), c_userId+",")){
			if(type.equals("0")||type.equals("2")){
				myAttention--;
				attentionEachOther--;
				session.setAttribute("blog_myAttention", myAttention);
				session.setAttribute("blog_attentionEachOther", attentionEachOther);
			}else if(type.equals("1")){
				attentionMe--;
				session.setAttribute("blog_attentionMe", attentionMe);
			}
			JSONObject json=new JSONObject();
			json.put("myAttention", myAttention);
			json.put("attentionEachOther", attentionEachOther);
			json.put("attentionMe", attentionMe);
			response.getWriter().print(json.toString());
		}
//		System.out.println("userId="+userId);
//		System.out.println("c_userId="+c_userId);
		
	}

}
